cba8e16b61cdf3c5077e878d412b332161deca4a,utils/src/com/cloud/utils/nio/NioClient.java,NioClient,init,#,47

Before Change


            sch.socket().bind(addr);
        }

        InetSocketAddress addr = new InetSocketAddress(_host, _port);
        try {
        	sch.connect(addr);
        } catch (IOException e) {
        	_selector.close();
        	throw e;
        }

        SSLEngine sslEngine = null;
        try {
        	// Begin SSL handshake in BLOCKING mode
        	sch.configureBlocking(true);

        	SSLContext sslContext = Link.initSSLContext(true);
        	sslEngine = sslContext.createSSLEngine(_host, _port);
        	sslEngine.setUseClientMode(true);

        	Link.doHandshake(sch, sslEngine, true);
        	s_logger.info("SSL: Handshake done");
        } catch (Exception e) {
        	_selector.close();
        	throw new IOException("SSL: Fail to init SSL! " + e);
        }
        
        sch.configureBlocking(false);
        Link link = new Link(addr, this);
        link.setSSLEngine(sslEngine);
        SelectionKey key = sch.register(_selector, SelectionKey.OP_READ);
        link.setKey(key);
        key.attach(link);
        // Notice we've already connected due to the handshake, so let's get the
        // remaining task done
        Task task = _factory.create(Task.Type.CONNECT, link, null);

After Change


                sch.socket().bind(addr);
            }

            addr = new InetSocketAddress(_host, _port);
            sch.connect(addr);
        } catch (IOException e) {
        	_selector.close();
        	throw e;
        }

        SSLEngine sslEngine = null;
        try {
        	// Begin SSL handshake in BLOCKING mode
        	sch.configureBlocking(true);

        	SSLContext sslContext = Link.initSSLContext(true);
        	sslEngine = sslContext.createSSLEngine(_host, _port);
        	sslEngine.setUseClientMode(true);

        	Link.doHandshake(sch, sslEngine, true);
        	s_logger.info("SSL: Handshake done");
        } catch (Exception e) {
        	_selector.close();
        	throw new IOException("SSL: Fail to init SSL! " + e);
        }
        
        Task task = null;
        try {
            sch.configureBlocking(false);
            Link link = new Link(addr, this);
            link.setSSLEngine(sslEngine);
            SelectionKey key = sch.register(_selector, SelectionKey.OP_READ);
            link.setKey(key);
            key.attach(link);
            // Notice we've already connected due to the handshake, so let's get the
            // remaining task done
            task = _factory.create(Task.Type.CONNECT, link, null);